﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Business.DwzFrame;
using NHibernate;
using ZLCMS.Data.Model;
using ZLCMS.Business.Util;

namespace ZLCMS.Web.SystemManage.Template.Template
{
    public partial class TemplatePageList : System.Web.UI.Page
    {
        protected FrameHelper _framePage;
        protected void Page_Load(object sender, EventArgs e)
        {
            _framePage = new FrameHelper(this);


            int pageSize = _framePage.IsAjaxPagerPostBack ? _framePage.PageSize : 20;
            int pageIndex = _framePage.IsAjaxPagerPostBack ? _framePage.PageIndex : 1;

            using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
            {
                string sql = "from CmsTemplatePage where 1=1 and TempId=:tid ";

                IQuery query = session.CreateQuery("select count(*) " + sql).SetParameter("tid", Int32.Parse(Request["tid"]));

                _framePage.RecordCount = Convert.ToInt32(query.UniqueResult());

                query = session.CreateQuery(sql + "order by PageLevel, Sort").SetParameter("tid", Int32.Parse(Request["tid"]));

                repeater1.DataSource = query.SetMaxResults(pageSize)
                    .SetFirstResult((pageIndex - 1) * pageSize)
                    .List<CmsTemplatePage>();
            }
            repeater1.DataBind();
        }


        protected string GetContent(object item)
        {
            CmsTemplatePage upage = item as CmsTemplatePage;
            string result = "<a style='color:#0C0C0C'>管理</a>";
            //""
            //if (upage.Kind != "default")
            {
                result = "<a href='/SystemManage/Template/Template/";
                if (upage.Kind == "list")
                {
                    result += "DocList.aspx";
                }
                else
                {
                    result += "DocDetail.aspx";
                }
                result += "?src=man&tempid=" + upage.Id + "'";
                result += " target='navTab' rel='";

                if (upage.Kind == "list")
                {
                    result += "DocList";
                }
                else
                {
                    result += "DocDetail";
                }
                result += "' title='" + upage.Name + "'>内容管理</a>";

            }
            return result;

        }
    }
}